class TG_PlayerController extends UDKPlayerController;

// SaveGame Variables
/** Declare our SaveGameBase. */
var SaveGameBase SGB;
/** Folder name that will be used in SaveGame() and LoadGame(). Defined in DefaultProperties */
var string FolderName; 
/** Save File name. Should be same in SaveGame and LoadGame. Defined in DefaultProperties */
var string SaveFileName;
/** Your custom file extension. Use any extension you want. Eg: ".bin" or ".sav". Defined in DefaultProperties */
var string SaveFileExtension;
// End of SaveGame Variables

/** Mouse Hit Position.*/
var vector PlaneHitPos;

  //////////////////////////////////////////////////////////////////////////////////////////////////////////
 //											PlayerControlCode											 //
//////////////////////////////////////////////////////////////////////////////////////////////////////////

function UpdateRotation(float DeltaTime){
   local Rotator   targetRotation;
   local float     hitLength;
   local TG_InterfaceHUD   playerHud;
   local TG_PlayerPawn  TitanPlayerpawn;

   if (self.Pawn != None)
   {
      TitanPlayerPawn = TG_PlayerPawn(self.Pawn);
			
         playerHud = TG_InterfaceHUD(myHUD);

         // calc the player/world plane > deproj mouse ray intersection
         hitLength = -((vect(0,0,1) dot (playerHud.CachedMouseWorldOrigin - TitanPlayerPawn.Location)) / (vect(0,0,1) dot playerHud.CachedMouseWorldDirection));      
         PlaneHitPos = (playerHud.CachedMouseWorldOrigin + playerHud.CachedMouseWorldDirection * hitLength);
		
         targetRotation = pawn.GetBaseAimRotation();
         targetRotation.Yaw = rotator(PlaneHitPos - TitanPlayerPawn.Location).Yaw; // only update yaw

         Pawn.FaceRotation(targetRotation, DeltaTime);
         }
	 else
	 {
         super.UpdateRotation(DeltaTime);
	 }
}


state PlayerWalking
{
ignores SeePlayer, HearNoise, Bump;

   function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
   {
      if( Pawn == None )
      {
         return;
      }

      if (Role == ROLE_Authority)
      {
         // Update ViewPitch for remote clients
         Pawn.SetRemoteViewPitch( Rotation.Pitch );
      }
      //Forces WASD to work properly!
      Pawn.Acceleration.X = 1 * PlayerInput.aBaseY  * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;;
      Pawn.Acceleration.Y = 1 * PlayerInput.aStrafe * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
      Pawn.Acceleration.Z = 0;
   }
}

  //////////////////////////////////////////////////////////////////////////////////////////////////////////
 //											PlayerControlCode											 //
//////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////
///																										 ///
///											Save Game Code												 ///
///																										 ///
///																										 ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
/** Saves the game. Bind this function to a key (like F5 or F6 or something like that) in DefaultInput.ini */
exec function SaveGame() 
{
    /** The string that will hold the absolute path of save location */
    local string SaveLoc;
    
    /** Since we extended the SaveGameBase from Object we must use "new" to create a new one */
    SGB = new class'SaveGameBase';
    
    /** Assign the players position to Loc variable inside SaveGameBase (SGB) */
    SGB.Loc = TG_PlayerPawn(self.Pawn).Location;
    
    /** Calls the DLLFunction which returns MyDocuments\FolderName\SaveFileName.SaveFileExtension */
    SaveLoc = SGB.SaveGameToMyDocuments(FolderName, SaveFileName, SaveFileExtension);
    
    /** Finally call the Engine Function to save all the SGB variables to the specified location */
    class'Engine'.static.BasicSaveObject(SGB, SaveLoc, true, SGB.SAVE_VERSION);
    
    /** [TESTING ONLY] */
    WorldInfo.Game.Broadcast(self, "Game Saved.");
    WorldInfo.Game.Broadcast(self, SaveLoc);
    WorldInfo.Game.Broadcast(self, "Player Position: "$SGB.Loc);
}

/** Loads the game. */
exec function LoadGame(int LoadVersion)
{
    /** Holds the path to load the save game */
    local string LoadLoc;
    SGB = new class'SaveGameBase';
    
    /** Calls the DLLFunction which returns MyDocuments\FolderName\SaveFileName_LoadVersion.SaveFileExtension */
    LoadLoc = SGB.LoadGameFromMyDocuments(FolderName, SaveFileName, SaveFileExtension, string(LoadVersion));
    
    /** If everything goes well and SGB.SAVE_VERSION is correct then load the file */
    if (class'Engine'.static.BasicLoadObject(SGB, LoadLoc, true, SGB.SAVE_VERSION))
    {
        /** Change the players position to whatever is defined in SGB.Loc */
        TG_PlayerPawn(self.Pawn).SetLocation(SGB.Loc);
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
///																										 ///
///											Save Game Code												 ///
///																										 ///
///																										 ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////	
defaultproperties
{
	CameraClass=class'TG_Camera'
	// Set the input class to the mouse interface player input
	InputClass=class'TG_InterfacePlayerInput'
	
    FolderName = "Saved Games\\Titan" //For multiple folders: "My Company Game\\My Game Name\\Save Games". It is IMPORTANT to set double slash!!
    SaveFileName = "Save" //The file name that will be used in SaveGame and LoadGame.
    SaveFileExtension = ".titz" //File Extension. You can use any extension you want.
}  